﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BoggleSolver {
    class Program {
        
        static void Main(string[] args) {
            System.IO.StreamReader myFile = new System.IO.StreamReader("../../words.txt");
            Boggle boggle = new Boggle();
            List<string> words = new List<string>();
            while (!myFile.EndOfStream)
                words.Add(myFile.ReadLine());
            myFile.Close();

            Console.WriteLine("What is the boggle grid?");
            Console.WriteLine("(For instance abcd efgh ijkl mnop)");
            Console.WriteLine("****");

            string grid = Console.ReadLine();
            var sw = new System.Diagnostics.Stopwatch();
            var sGrid = grid.Split(' ');
            Console.WriteLine("****");

            Console.WriteLine("...running solver for grid");
            PrintGrid(sGrid);
            Console.WriteLine("****");

            sw.Start();
            var results = boggle.SolveBoggle(sGrid, words);
            sw.Stop();

            results.Sort();
            foreach (string s in results)
                Console.WriteLine(s);
            Console.WriteLine(results.Count.ToString() + " results found in " + sw.ElapsedMilliseconds.ToString() + "ms");
            Console.ReadKey();
        }

        static void PrintGrid(string[] sGrid) {
            string line = "";
            for (int i = 0; i < sGrid.Length; i++)
                line += "+---";
            line += "+";
            Console.WriteLine(line);
            foreach (string temp in sGrid) {
                string dataLine = "|";
                foreach (char c in temp)
                    dataLine += " " + c + " |";
                Console.WriteLine(dataLine);
                Console.WriteLine(line);
            }
        }
    }
}
